<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程追回</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
    <style>
        .layui-bg-gray{background: #FBFCFE!important;font-weight: bold}
    </style>
</head>
<body>

<script type="text/html" template>
    <div class="ccpui-tablesize user" style="padding: 16px">
        <table class="layui-table" style="margin: 0">
            <colgroup>
                <col width="10">
                <col width="200">
            </colgroup>
            <tbody>
            <tr id="sendMethod">
                <td class="layui-bg-gray">发送方式</td>
                <!--<td><input id="input" name="informType" type="checkbox" title="站内消息"><span id="msg"></span></td>-->
                <td>
                    <#list handlersMap?keys as key>
                    <input type="checkbox"  lay-filter="informType" name="informType" lay-skin="primary" value="${key}" checked="checked"
                    />
                    <span style="line-height: 28px;" id="msg">
                    ${handlersMap[key].title }
                    </span>
                    </#list>
                </td>
            </tr>
            <tr id="message">
            </tr>
            </tbody>
        </table>
    </div>

</script>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table', 'layer', 'form', 'setter','publicMethods'], function (d) {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var $ = layui.$;
        var publicMethods=layui.publicMethods;
        var setter = layui.setter;

        var runId = "${runId}";
        var backToStart = "${backToStart}";

        checkRedo();

        function checkRedo() {
            $.ajax({
                url: serverPath.qbdmsPath + setter.workflowLinkPath + "processRun/checkRedo?runId=" + runId,
                type: "post",
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        $('#message').html('<th class="layui-bg-gray">不能追回原因</th><td><textarea name="desc" placeholder="请输入内容" class="layui-textarea" style="color: #af0000" disabled>' + data.msg + '</textarea></td>');
                        $('#sendMethod').hide();
                        $('#recover').hide();
                    } else {
                        $('#message').html('<th class="layui-bg-gray">追回原因</th>  <td><textarea name="desc" placeholder="请输入内容" class="layui-textarea" id="recoverReason"></textarea></td>');
                    }
                },
                error: function () {
                    alert("请联系管理员！！！");
                }
            })
        }

        //关闭该页面弹窗
        function closeOpen(){
            parent.layer.closeAll();
        }

        window.recover = function (callback) {
            if ($('#recoverReason').val() != null && $('#recoverReason').val() != '') {
                layer.confirm(publicMethods.confirmStyle("确认要追回该数据吗？"),{title: false,skin: 'confirm-class'}, function () {
                    $.ajax({
                        url: serverPath.qbdmsPath + setter.workflowLinkPath + "processRun/recover",
                        data:{ runId:runId
                                ,backToStart:backToStart
                                ,informType:$('input[name="informType"]').val()
                                ,opinion:$('#recoverReason').val()
                        },
                        type: "post",
                        dataType: 'json',
                        success: function (res) {
                            if(res.code==0) {
                                layer.alert(publicMethods.confirmStyle(res.msg),{title: false,skin: 'confirm-class'},function () {
                                        closeOpen();
                                });
                                //关闭弹窗，刷新页面
                                if (callback) { callback(); }
                            }else{
                                layer.alert(publicMethods.confirmStyle(res.msg),{title: false,skin: 'confirm-class'},function () {
                                    closeOpen();
                                });
                            }
                        },
                        error: function () {
                            layer.open({
                                title: '提示'
                                , content: '追回失败！'
                                , yes: function () {
                                    closeOpen();
                                }
                            });
                        }
                    });
                });

            } else {
                layer.alert(publicMethods.confirmStyle("必须填写追回原因！"),{title: false,skin: 'confirm-class'});
            }

        };

    })


</script>
</body>
</html>
